<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客管理</title>
    <th:block th:replace="./common/common-admin :: css"></th:block>
</head>
<body>

<!--导航栏-->
<nav th:replace="./common/common-admin :: menu(1)"></nav>

<div class="m-padded-tb-hugex">
    <div class="ui attached pointing menu">
        <div class="ui container">
            <div class="right menu">
                <a href="#" th:href="@{/admin/blogs/addBlog}" class=" item">发布</a>
                <a href="#" th:href="@{/admin/blogs}" class="teal active item">列表</a>
            </div>
        </div>
    </div>
</div>

<br>
<br>
<br>

<!--中间内容-->
<div  class="">
    <div class="ui container">
        <div  class="ui secondary segment form">
            <input type="hidden" name="page" >
            <div class="inline fields">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <div class="field">
                    <div class="ui labeled action input">
                        <div class="ui type selection dropdown">
                            <input type="hidden" name="typeId">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div class="item" data-value="1">我的故事</div>
                            </div>
                        </div>
                        <button id="clear-btn" class="ui compact button">clear</button>
                    </div>

                </div>

                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>

                <div class="field">
                    <button  type="button" id="search-btn" class="ui mini teal basic button"><i class="search icon"></i>搜索</button>
                </div>
            </div>
        </div>

        <div id="table-container">
            <table th:fragment="blogList" class="ui compact teal table">
                <thead>
                <tr align="center">
                    <th>ID</th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>推荐</th>
                    <th>状态</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>

                <tbody>
                <tr align="center" th:each="blog,iterStat : ${pageInfo.list}">
                    <td th:text="${iterStat.count}">1</td>
                    <td th:text="${blog.title}">大圣，此去欲何?</td>
                    <td th:text="${blog.getType().name}">我的故事</td>
                    <td th:text="${blog.recommend} ? '是':'否'">是</td>
                    <td th:text="${blog.published} ? '发布':'草稿'">草稿</td>
                    <td th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2020-01-02 05:20</td>
                    <td>
                        <a href="#" th:href="@{/admin/blogs/editBlog/{id}(id=${blog.id})}" class="ui mini teal basic button">编辑</a>
                        <a href="#" th:href="@{/admin/blogs/deleteBlog/{id}(id=${blog.id})}" onclick="return confirm('确定要删除该文章吗？三思啊! 删了可就没了！')" class="ui mini red basic button">删除</a>
                    </td>
                </tr>
                </tbody>

                <tfoot>
                <tr>
                    <th colspan="7">
                        <div class="ui inverted divided stackable grid">
                            <div class="three wide column" align="center">
                                <a class="item" th:href="@{/admin/blogs(pn=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}" th:unless="${pageInfo.isFirstPage}">上一页</a>
                            </div>

                            <div class="ten wide column" align="center">
                                <p>第 <span th:text="${pageInfo.pageNum}"></span> 页，共 <span th:text="${pageInfo.pages}"></span> 页，有 <span th:text="${pageInfo.total}"></span> 篇文章</p>
                            </div>

                            <div class="three wide column" align="center">
                                <a class="item" th:href="@{/admin/blogs(pn=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}" th:unless="${pageInfo.isLastPage}">下一页</a>
                            </div>
                        </div>
                        <div align="center">
                            <a href="#" th:href="@{/admin/blogs/addBlog}">
                                <button type="button" class="ui teal button m-mobile-wide m-margin-top"><i class="pencil icon"></i>新增</button>
                            </a>
                        </div>
                    </th>
                </tr>
                </tfoot>

            </table>

            <div class="ui success message">
                <i class="close icon"></i>
                <div class="">提示：操作成功！</div>
            </div>

        </div>

    </div>
</div>


<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<!--底部栏-->
<footer th:replace="./common/common-admin :: footer"></footer>

<!--js-->
<th:block th:replace="./common/common-admin :: script"></th:block>

<script>

    //消息提示关闭初始化
    $('.message .close')
        .on('click', function () {
            $(this)
                .closest('.message')
                .transition('fade');
        });

    $('#clear-btn')
        .on('click', function() {
            $('.ui.type.dropdown')
                .dropdown('clear');
        });

    function page(obj) {
        $("[name='page']").val($(obj).data("page"));
        loaddata();
    }

    $("#search-btn").click(function () {
        $("[name='page']").val(0);
        loaddata();
    });
    function loaddata() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
            title : $("[name='title']").val(),
            typeId : $("[name='typeId']").val(),
            page : $("[name='page']").val()
        });
    }

</script>
</body>
</html>